<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorator="layout">

<div layout:fragment="body">
    <div id="toptoolbar"></div>
    <div id="searchformDiv">
        <form id='searchform' class="l-search-form" th:action="@{/loanRequest/export/potential}">
            <div class="layui-inline">
                <input type="text" th:placeholder="#{estateEvalInfo.propertyType}" liger="{type:'comboBox', valueFieldID:'search_EQ_estateEvalInfo.propertyType',configCode:'PROPERTY_TYPE'}"/>
                <input id="search_EQ_estateEvalInfo.propertyType" name="search_EQ_estateEvalInfo.propertyType" style="display: none;">
            </div>
            <div class="layui-inline">
                <input type="text" class="l-text" name="search_LIKE_estateEvalInfo.houseAddress" th:placeholder="#{estateEvalInfo.houseAddress}"/>
            </div>
            <div class="layui-inline">
                <input type="text" class="l-text" name="search_LIKE_user.realname" th:placeholder="#{loanRequest.managerId}"/>
            </div>
            <div class="layui-inline">
                <input type="text" class="l-text" name="search_LIKE_channel.name" th:placeholder="来源名称"/>
            </div>
            <div class="layui-inline">
                <input type="text" class="l-text" name="search_LIKE_channelForNo.name" th:placeholder="渠道名称"/>
            </div>
            <div class="layui-inline">
                <input type="text" class="l-text" name="search_LIKE_mobile" th:placeholder="#{loanRequest.mobile}"/>
            </div>
            <br>
            <div class="layui-inline">
                <input type="text" ltype="text" th:placeholder="查询日期" name="search_GTE_createdAt" liger="{type : 'date'}"/>
            </div>
            至
            <div class="layui-inline">
                <input type="text" ltype="text" th:placeholder="查询日期" name="search_LTE_createdAt" liger="{type : 'date'}"/>
            </div>
            <div class="layui-inline">
                <input type="reset" class="l-reset" th:value="#{reset}" />
                <input type="button" class="l-search" th:value="#{search}" onclick="f_search();" />
            </div>
        </form>
    </div>
    <div id="maingrid"></div>
</div>

<!-- page specific plugin scripts -->
<script type="text/javascript" layout:fragment="script">/*<![CDATA[*/
var maingrid;
var topToolBar;
$(function() {
    maingrid = newGrid("maingrid", {
        columns : [
            {
                display : '[[#{estateEvalInfo.propertyType}]]',
                name : 'config_estateEval_propertyType',
                align : 'center',
                width : 80
            },{
                display : '[[#{estateEvalInfo.houseAddress}]]',
                name : 'estateEval_houseAddress',
                align : 'left',
                width : 200
                ,render: function (row) {
                    if (row.estateEvalId == null){
                        return "";
                    }
                    var operate ='&nbsp;<a href="javascript:void(0);" onclick="viewEstateEval(\'' + row.estateEvalId + '\')">' + row.estateEval_houseAddress + '</a>';
                    return operate;
                }
            },
            {
                display : '[[#{estateEvalInfo.roomSize}]]',
                name : 'estateEval_roomSize',
                align : 'right',
                width : 60
            },
            {
                display : '[[#{estateEvalInfo.houseTotalPrice}]]',
                name : 'estateEval_houseTotalPrice',
                align : 'right',
                type : 'currency',
                width : 120
            },{
                display : '[[#{loanRequest.managerId}]]',
                name : 'manager_realname',
                align : 'left',
                width : 120
            },{
                display : '[[#{loanRequest.channelId}]]',
                name : 'channel_name',
                align : 'left',
                width : 120
            },{
                display : '[[#{loanRequest.channelNo}]]',
                name : 'channelNo_name',
                align : 'left',
                width : 120
            },{
                display : '[[#{loanRequest.mobile}]]',
                name : 'mobile',
                align : 'center',
                width : 100
            },{
                display : '[[#{loanRequest.area}]]',
                name : 'area_name',
                align : 'center',
                width : 60
            },{
                   display : '[[#{createdAt}]]',
                name : 'createdAt',
                type : 'datetime',
                width : 120
            },{
                   display : '[[#{updatedAt}]]',
                name : 'updatedAt',
                type : 'datetime',
                width : 120
            }],
        url : '/loanRequest/potential/list'
    });

    topToolBar = $("#toptoolbar").ligerToolBar({
        items : [ {
            text : '查看',
            click : viewClick,
            icon : 'view'
        }, {
            text : '转为意向客户',
            click : intentClick,
            icon : 'edit'
        }, {
            text : '导出',
            click : exportClick,
            icon : 'view'
        } ]
    });

    maingrid.setHeight(document.documentElement.clientHeight - $("#toptoolbar").height() -  $("#searchform").height() - 18);

    if ('[[${isParent}]]'){
            topToolBar.addItem({
            text : '分配',
            click : f_user_click,
            icon : 'ok'
        });
    }
});

function addClick(item) {
    openForm({url : '/loanRequest/form',title : '新增'})
}

function intentClick(item) {
    isSingleSelected(maingrid, function(row) {
        if (row['managerId'] == null){
            showError("请先分配负责人");
            return;
        }
        if (row['managerId'] != '[[${currentUserId}]]' && !'[[${isGlobal}]]'){
            showError("您不是负责人，无法转为意向客户 ");
            return;
        }
        openForm({
            url : '/loanRequest/form?id=' + row['id'],
            title : '意向提交'
        });
    });
}

function deleteClick(item) {
    isSingleSelected(maingrid, function(row) {
        showConfirm('确定要删除', function(yes) {
            if (yes) {
                ajaxDo('/loanRequest/delete?id=' + row['id']);
            }
        });
    });
}

function viewClick(item) {
    isSingleSelected(maingrid, function(row) {
        openDialog({
            title: '查看',
            url : '/loanRequest/view?id=' + row['id']});
    });
}

function viewEstateEval(id) {
        openDialog({
            title: '查看',
            url : '/estateEvalInfo/view?id=' + id});
}

function f_search() {
    loadGridData(maingrid, "searchform");
}

function f_reload() {
    maingrid.loadData(true);
}

function f_user_click(item) {
    isSelected(maingrid, function (rows) {
        return openSelect({
            title: '请选择负责人',
            url: '/loanRequest/select?isMultiSelect=false',
            height: 460,
            callback: function (item, dialog) {
                var fn = getDialogFunc(item, dialog, 'f_select');
                var data = fn();
                if (!data || data.selectIds == '') {
                    showError('请选择负责人!');
                    return;
                }
                ajaxDo('/loanRequest/allocation?ids=' + idStr(rows) + '&userId=' + data.selectIds);
                closeDialog(item, dialog);
            }
        });
    });
}

function exportClick(item) {
    $("#searchform").submit();
}
/*]]>*/</script>
</html>
